package net.csdn.business.discuss.api.controller;

import com.alibaba.fastjson2.JSON;
import lombok.extern.slf4j.Slf4j;
import net.csdn.business.discuss.api.facade.DiscussWrapperFacade;
import net.csdn.business.discuss.api.model.dto.*;
import net.csdn.business.discuss.api.model.vo.CategoryTypeVO;
import net.csdn.business.discuss.api.model.vo.DiscussCategoryVO;
import net.csdn.business.discuss.api.service.IDiscussCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @ClassName webhook配置信息Controller
 * @Description TODO
 * @Author zhangyl
 * @Date 2023/4/23 16:14
 */
@Slf4j
@RestController
@RequestMapping("/api/v1/discuss/category")
public class DiscussCategoryController
{
    @Autowired
    private IDiscussCategoryService discussCategoryService;

    @Autowired
    private DiscussWrapperFacade discussWrapperFacade;

    /**
     * 查询dicuess的分类的类型
     */
    @GetMapping("/type")
    public List<CategoryTypeVO> getEvent(){
        return discussCategoryService.getTypeList();
    }


    /**
     * 根据所属id查询讨论分类列表
     */
    @GetMapping("/list/{sourceId}/{sourceType}")
    public List<DiscussCategoryVO> getListBySourceId(@PathVariable("sourceId")String sourceId,@PathVariable("sourceType")Integer sourceType)
    {
        return discussCategoryService.getListBySourceId(sourceId,sourceType);
    }


    /**
     * 根据分组id查询讨论分类列表
     */
    @GetMapping("/section/{sectionId}")
    public List<DiscussCategoryVO> getListBySectionId(@PathVariable("sectionId")String sectionId)
    {
        return discussCategoryService.getListBySectionId(sectionId);
    }


    /**
     * 根据所属id查询讨论分类列表和分组列表
     */
    @GetMapping("/all/{sourceId}/{sourceType}")
    public Map<String,List> getCategoryAndSectionList(@PathVariable("sourceId")String sourceId,@PathVariable("sourceType")Integer sourceType)
    {
        return discussCategoryService.getCategoryAndSectionList(sourceId,sourceType);
    }


    /**
     * 根据id获取讨论分类详情
     */
    @GetMapping(value = "/{id}")
    public DiscussCategoryVO getInfo(@PathVariable("id") String id)
    {
        return discussCategoryService.selectDiscussCategoryById(id);
    }

  /*  *//**
     * 讨论分类初始化
     *//*
    @PostMapping("/init")
    public Integer initDiscussCategory(@RequestBody @Validated InitDiscussDTO params)
    {
        return discussCategoryService.initDiscussCategory(params);
    }*/


    /**
     * 新增讨论分类
     */
    @PostMapping
    public String add(@RequestBody @Validated NewDiscussCategoryDTO discussCategory)
    {
        return discussWrapperFacade.addCategory(discussCategory);
    }

    /**
     * 修改讨论分类
     */
    @PutMapping
    public Integer edit(@RequestBody @Validated UpdateDiscussCategoryDTO discussCategory)
    {
        return discussWrapperFacade.editCategory(discussCategory);
    }

    /**
     * 删除讨论分类
     */
    @DeleteMapping
    public Integer delete(@RequestBody @Validated DeleteResourceDTO params)
    {
        return discussWrapperFacade.deleteCategory(params);
    }


    /**
     * 更新审核状态
     */
    @PostMapping("/updateAuditStatus")
    public Integer updateAuditStatus(@RequestBody @Validated UpdateAuditStatusDTO params){
        log.info("discuss update audit status params:{}", JSON.toJSONString(params));
        return discussCategoryService.updateAuditStatus(params);
    }
}
